/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 * 
 * @param str string字符串 
 * @param pattern string字符串 
 * @return bool布尔型
 */
 function match( str ,  pattern ) {
  // write code here
  let m = str.length
  let n = pattern.length
  let match = new Array(m+1).fill(0).map(v => new Array(n+1).fill(0))
  for(let i = 0;i < m+1;i++){
    for(let j = 0;j < n+1;j++){
      if(j === 0){
        if(i === 0){
          match[i][j] = true
        }
      }else{
        if(pattern[j-1] !== '*'){
          if(i >= 1 && (str[i-1] === pattern[j-1] || pattern[j-1] === '.')){
            match[i][j] = match[i-1][j-1]
          }
        }else{
          if(j >= 2){
            match[i][j] |= match[i][j-2]
            if((j >= 2 && i >= 1) && ((str[i-1] === pattern[j-2]) || pattern[j-2] === '.')){
              match[i][j] |= match[i-1][j]
            }
          }
        }
      }
    }
  }
  return match[m][n]
}
module.exports = {
  match : match
};